package com.wwz.frame.controller;

import com.wwz.frame.entity.User;
import com.wwz.frame.entity.ValueDemo;
import io.swagger.annotations.Api;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @Description 属性设置、自定义属性使用  测试类
 * @Author wwz
 * @Date 2019/08/08
 * @Param
 * @Return
 */
@Api(value = "valueController", tags = "自定义属性测试")
@RestController
@RequestMapping("/value")
public class ValueController {
    @Autowired
    private ValueDemo value;
    @Autowired
    private User user;
    @Autowired
    private Environment environment;

    @GetMapping
    public String value() throws IOException {
        System.out.println(value.getNormal());
        System.out.println(value.getOsName());
        System.out.println(value.getRandomNumber());
        // 获取文件内容
        System.out.println(IOUtils.toString(value.getTestFile().getInputStream()));
        // 取到对应url的页面属性
        System.out.println(IOUtils.toString(value.getTestUrl().getInputStream()));
        System.out.println(value.getUserName());
        return value.toString();
    }

    @GetMapping("/user")
    public String user() {
        return user.toString();
    }

    @GetMapping("/environment")
    public String environment() {
        // 取值方式 return environment.getProperty("value.user.name");
        return environment.toString();
    }
}
